package com.fingard.dsp.web.runtime;

import com.fingard.FGBiz;
import com.fingard.dsp.web.page.PageBase;

public class RuntimeManager {

	private RequestRecord[] reqRdList;
	public RuntimeManager(){
		reqRdList = new RequestRecord[10];
		for(int i=0;i<reqRdList.length;i++){
			reqRdList[i] = new RequestRecord();
		}
	}
	
	/**根据pReqId的最后5位数字取得固定的索引*/
	private int getIdx(String pReqId){
		int sumId = 0;
		String cutId = pReqId;
		if(cutId.length()<5){
			cutId = "12345"+cutId;
		}
		cutId = cutId.substring(cutId.length()-5, cutId.length());
		try{
			for(int i=0;i<cutId.length();i++){
				sumId += Integer.parseInt(cutId.charAt(i)+"");
			}
		}catch(Exception ex){
			FGBiz.limitMsg.exception(this.getClass().getName(), ex);
		}
		int idx = sumId%reqRdList.length;
		return idx;
	}
	
	public void addReq(String pReqId, PageBase pPage){
		int idx = getIdx(pReqId);
		reqRdList[idx].add(pReqId, pPage);
	}
	
	public void removeReq(String pReqId){
		int idx = getIdx(pReqId);
		reqRdList[idx].remove(pReqId);
	}
	
	public PageBase getReq(String pReqId){
		int idx = getIdx(pReqId);
		return reqRdList[idx].getPageReq(pReqId);
	}
}
